/*
 * estructuras.h
 *
 *  Created on: 25/10/2011
 *      Author: utn_so
 */

#ifndef ESTRUCTURAS_H_
#define ESTRUCTURAS_H_

#define FUSE_USE_VERSION 26

#define SIZE_SECTOR 512
#define SIZE_CLUSTER 8
#define SIZE_FAT_CLUSTERS 65535
#define SIZE_BLOCK 8
#define SIZE_ENTRADA_DATA_REGION 32
#define SIZE_ENTRADA_FAT 4

#define BOOT_SECTOR 0
#define RESERVED_SECTOR_COUNT 32//leer del boot
#define NUMBER_OF_FATS 2//leer del boot
#define SECTORS_PER_FAT 1024//leer del boot
#define ROOT_ENTRIES 0//leer del boot
#define LONGITUD_TABLA_FAT ((SECTORS_PER_FAT * SIZE_SECTOR)/4)
#define DIR_FAT1 RESERVED_SECTOR_COUNT
#define DIR_DATA_REGION RESERVED_SECTOR_COUNT + ( NUMBER_OF_FATS * SECTORS_PER_FAT )
#define CANT_ENTRADAS_DATA_REGION_PORCLUSTER ((SIZE_SECTOR/SIZE_ENTRADA_DATA_REGION)*SIZE_CLUSTER)
#define CANT_ENTRADAS_FAT_POR_SECTOR ( SIZE_SECTOR / SIZE_ENTRADA_FAT )

#define ERROR_BYTES_NOT -1
#define ERROR_GUARDAR_DATOS_APARTIR_DE_OFFSET -1
#define ERROR_LOCATION_FILE -1
#define SUCCESSFUL 0

#include <stdint.h>//uintN_t N bits
#include <stdlib.h>

//****************************************************************************************************


/*typedef struct {
        char *bytes;
        uint32_t sectorReal;
} Sector;
*/
typedef struct {
        uint8_t bytes[SIZE_SECTOR];
        int32_t sectorReal;
} Sector;

typedef struct {
         Sector sectores[SIZE_CLUSTER];
} Cluster;

typedef struct {
         Sector sectores[SIZE_CLUSTER];
} Bloque;

typedef struct{
        uint32_t entradasFat[LONGITUD_TABLA_FAT];
}FatRegion;

struct nodoListaClusters{
        uint32_t cluster;
        struct nodoListaClusters *clusterSgte;
};

struct nodoListaLFN{
        char lfn[13];
        uint8_t sectorCache;
        uint16_t byteCache;
        struct nodoListaLFN *lfnSgte;
};
/*
typedef struct{
		uint8_t bytes[SIZE_BLOCK*SIZE_SECTOR];
} CacheFat;
*/
typedef struct{
		Sector sectores[SIZE_BLOCK];
		uint32_t sectorReal;
} CacheFat;

typedef struct{
        uint8_t bitmap[LONGITUD_TABLA_FAT];
} VecBitmap;

typedef struct{
	uint8_t nroSector;
	uint16_t bloque;
	uint8_t nroEntrada;
} UbicacionEntradaFat;

typedef struct{
	uint32_t sector;
	uint32_t bloque;
	uint32_t byteComienzoEntrada;
} EntradaFat;

typedef struct{
	uint16_t nroSector;
	uint16_t nroByte;
	uint16_t nroByteEntradaSgte;
	uint16_t nroSectorEntradaSgte;
} UbicacionCache;

typedef struct{
	uint8_t sequenceNumber;
	uint16_t nameLFN1[5];
	uint8_t attributes;
	uint8_t reserved;
	uint8_t checksum;
	uint16_t nameLFN2[6];
	uint16_t firstCluster;
	uint16_t nameLFN3[2];
} LFN;

typedef struct{
	int8_t bloque;
	uint8_t sector;
	uint16_t byte;
	int8_t error;
} aux;

typedef CacheFat CapaDireccionamiento;
typedef struct nodoListaClusters NodoListaClusters;
typedef NodoListaClusters *PtrListaClusters;
typedef struct nodoListaLFN NodoListaLFN;
typedef NodoListaLFN *PtrListaLFN;

VecBitmap vectorBitMap;
CacheFat cacheFat;
CapaDireccionamiento capaDir;


#endif /* ESTRUCTURAS_H_ */
